home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / falcon / programm.ing / nt_dsp1.lzh / NT_DSP1.MSA / FLOAT / FPFIX.ASM < prev    next >
Assembly Source File  |  1989-01-24  |  4KB  |  108 lines

  1. ;
  2. ; This program originally available on the Motorola DSP bulletin board.
  3. ; It is provided under a DISCLAIMER OF WARRANTY available from
  4. ; Motorola DSP Operation, 6501 Wm. Cannon Drive W., Austin, Tx., 78735.
  5. ; Last Update 5 Oct 87   Version 2.0
  6. ;
  7. fpfix   ident   2,0
  8. ;
  9. ; MOTOROLA DSP56000/1 FPLIB - VERSION 2
  10. ;
  11. ; FPFIX - FLOATING POINT TO FIXED POINT CONVERSION SUBROUTINE
  12. ;
  13. ; Entry points: fix_a   D = fix(A)
  14. ;               fix_x   D = fix(X)
  15. ;
  16. ;       m = 24 bit mantissa (two's complement, normalized fraction)
  17. ;
  18. ;       e = 14 bit exponent (unsigned integer, biased by +8191)
  19. ;
  20. ;       data = 56 bit fixed point data in standard integer/fractional
  21. ;              accumulator data representation.
  22. ;
  23. ; Input variables:
  24. ;
  25. ;   X   x1 = mx  (normalized)
  26. ;       x0 = ex
  27. ;
  28. ;   A   a2 = sign extension of ma
  29. ;       a1 = ma  (normalized)
  30. ;       a0 = zero
  31. ;
  32. ;       b2 = sign extension of ea (always zero)
  33. ;       b1 = ea
  34. ;       b0 = zero
  35. ;
  36. ; Output variables:
  37. ;
  38. ;   D    a = data
  39. ;
  40. ; Error conditions:     Set CCR L=1 if conversion overflow error.  That is,
  41. ;                       the input value was larger than +/- 256 and could
  42. ;                       not be represented in the standard 56 bit accumulator
  43. ;                       format.  Result is the maximum 56 bit fixed point
  44. ;                       value having the same sign as the floating point
  45. ;                       mantissa.  The CCR L bit remains set until cleared
  46. ;                       by the user.
  47. ;
  48. ; Assumes n0, m0, shift constant table and scaling modes
  49. ; initialized by previous call to the subroutine "fpinit".
  50. ;
  51. ; Alters Data ALU Registers
  52. ;       a2      a1      a0      a
  53. ;       b2      b1      b0      b
  54. ;               x0      y1
  55. ;
  56. ; Alters Address Registers
  57. ;       r0
  58. ;
  59. ; Alters Program Control Registers
  60. ;       pc      sr
  61. ;
  62. ; Uses 0 locations on System Stack
  63. ;
  64. ;
  65. fix_x   tfr     x0,b    x1,a            ;get mx,ex
  66. fix_a   tst     a       fp_space:fp_ebias,x0    ;check ma, get bias
  67.         jeq     done                    ;jump if ma = 0
  68.         sub     x0,b    #>8,x0          ;remove ea bias, get shift limit
  69.         jlt     _eneg                   ;jump if exponent < 0
  70.         jeq     done                    ;jump if exponent = 0
  71. ;
  72. ; exponent > 0
  73. ;
  74.         cmp     x0,b                    ;check left shift limit
  75.         jgt     _ehigh                  ;jump if exponent > 8
  76.         rep     b                       ;shift left b bits
  77.         asl     a                       ;shift data left
  78.         rts
  79. _ehigh  or      #$40,ccr                ;set L=1 for conversion overflow
  80.         tst     a                       ;check sign of ma
  81.         jpl     _fix1                   ;jump if ma positive
  82.         clr     a                       ;limit to maximum negative 56 bit value
  83.         move    #$80,a2                 ;set extension word
  84.         rts
  85. _fix1   clr     a                       ;limit to maximum positive 56 bit value
  86.         not     a                       ;set most significant word
  87.         move    a1,a0                   ;set least significant word
  88.         move    #$7f,a2                 ;set extension word
  89.         rts
  90. ;
  91. ; exponent < 0
  92. ;
  93. _eneg   abs     b       #>24,x0         ;fix exponent, get right shift limit
  94.         sub     x0,b    b1,r0           ;check for underflow, save exponent
  95.         jge     _elow                   ;jump if fixed point underflow
  96.         move    fp_space:(r0+n0),x0     a,y1    ;lookup shift factor, get ma
  97.         mpy     -y1,x0,a                ;denormalize ma
  98.         rts
  99. _elow   jeq     _shift                  ;jump if exponent = -24
  100.         cmp     x0,b    b1,r0           ;check for underflow, save exponent
  101.         jge     zero                    ;jump if data underflow
  102.         move    fp_space:(r0+n0),x0     a,y1    ;lookup shift factor, get ma
  103.         mpy     -y1,x0,a                ;denormalize ma
  104. _shift  tfr     a,b     a2,a            ;shift down 24 bits more
  105.         move    b1,a0
  106.         rts
  107.